package com.park.test.main;


import com.park.test.*;
import com.park.wx.WeiXinConnector;

/**
 * 菜单管理类,用于菜单的创建
 * 
 * @author Administrator
 * 
 */
public class MenuManager {
	
	static String APP_ID = WeiXinConnector.APP_ID;
	static String SECRET = WeiXinConnector.SECRET;
	static String domain = WeiXinConnector.DOMIAN;//"http://tuhao.viphk.ngrok.org";

	public static void main(String[] args) {
		
		getMenu();

		// 调用接口获取access_token
		AccessToken at = WeixinUtil.getAccessToken(APP_ID, SECRET);

		if (null != at) {
			// 调用接口创建菜单
			int result = WeixinUtil.createMenu(getMenu(), at.getToken());

			// 判断菜单创建结果
			if (0 == result)
				System.out.println("菜单创建成功！");
			else
				System.out.println("菜单创建失败，错误码：" + result);
		}
	}

	/**
	 * 组装菜单数据
	 * 
	 * @return
	 */
	private static Menu getMenu() {

		
		Menu menu = new Menu();
		
		//意外险菜单
		ViewButton ywx = new ViewButton();		
		ywx.setName("星座图腾");
		ywx.setType("view");
		ywx.setUrl(domain+"/m");
		
		
		/*//意外险菜单
		ViewButton bc = new ViewButton();		
		bc.setName("包车");
		bc.setType("view");
		bc.setUrl(domain+"/front/wxprerentdirectautofullorderinfo.action");
		
		ClickButton kefu = new ClickButton();
		kefu.setKey("10");
		kefu.setName("在线咨询");
		kefu.setType("click");
				
		ViewButton mo = new ViewButton();
		
		mo.setName("我的订单");
		mo.setSub_button(new Button[] {kefu});*/
		
		
		
		menu.setButton(new Button[]{ywx});
		
//		System.out.println("b1:" + b1.getUrl());
//		System.out.println("b2:" + b2.getUrl());
//		System.out.println("b3:" + b3.getUrl());
//		System.out.println("b4:" + b4.getUrl());

		return menu;
	}
}
